package com.weavernorth.attendance;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.schedule.BaseCronJob;


/**
 * @program: ecology_erdos
 * @description: 考勤异常提醒(每月1日提醒上个月异常考勤信息情况 。)
 * @author: zm
 * @create: 2020-01-06 15:38
 **/


public class AbnormalAttendMonth extends BaseCronJob {
    public static Log log = LogFactory.getLog(AbnormalAttendMonth.class.getName());

    @Override
    public void execute() {
        //数据库操作
        RecordSet rs = new RecordSet();
        //考勤异常工具类
        AbnormalUtil abnormalUtil = new AbnormalUtil();

        //查询前一月考勤异常的人员
        String sql = "select resourceid,sum(belate) belate ,sum(gravebelate) gravebelate," +
                "sum(leaveeearly) leaveeearly ,sum(graveleaveearly) graveleaveearly,sum(absenteeism) absenteeism," +
                "sum(forgotcheck) forgotcheck,sum(forgotbeginworkcheck) forgotbeginworkcheck" +
                "  from kq_format_total " +
                " where to_char(to_date(kqdate, 'yyyy-mm-dd'), 'yyyy-mm') =" +
                "(select to_char(sysdate - interval '1' month, 'yyyy-mm') from dual)  group by resourceid";
        log.info("查询前一个月考勤异常数据:" + sql);
        rs.executeQuery(sql);
        while (rs.next()) {
            StringBuffer strMess = new StringBuffer("您上个月");
            //人员id
            String strResourceid = Util.null2String(rs.getString("resourceid"));
            //迟到次数
            int intBelate = Util.getIntValue(rs.getString("belate"));
            if (intBelate != 0) {
                strMess.append("迟到次数为:" + intBelate + "次");
            }
            //严重迟到次数
            int intGravebelate = Util.getIntValue(rs.getString("gravebelate"));
            if (intGravebelate != 0) {
                strMess.append(",严重迟到次数为:" + intGravebelate + "次");
            }
            //早退次数
            int intLeaveeearly = Util.getIntValue(rs.getString("leaveeearly"));
            if (intLeaveeearly != 0) {
                strMess.append(",早退次数为:" + intLeaveeearly + "次");
            }
            //严重早退次数
            int intGraveleaveearly = Util.getIntValue(rs.getString("graveleaveearly"));
            if (intGraveleaveearly != 0) {
                strMess.append(",严重早退次数为:" + intGraveleaveearly + "次");
            }
            //旷工次数
            int intAbsenteeism = Util.getIntValue(rs.getString("absenteeism"));
            if (intAbsenteeism != 0) {
                strMess.append(",旷工次数为:" + intAbsenteeism + "次");
            }
            //下午漏签次数
            int intMoonForgotcheck = Util.getIntValue(rs.getString("forgotcheck"), 0);
            //上午漏签次数
            int intMornForgotcheck = Util.getIntValue(rs.getString("forgotbeginworkcheck"), 0);
            //总漏签次数
            int intForgotcheck = intMoonForgotcheck + intMornForgotcheck;
            if (intForgotcheck != 0) {
                strMess.append(",漏签次数为:" + intForgotcheck + "次,");
            }
            strMess.append("请您及时处理!");
            log.info("拼接的异常提醒信息:" + strMess);
            //创建考勤异常提醒流程
            abnormalUtil.createAbnormal(strResourceid, strMess.toString());

        }

    }
}
